﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharedLib.DataAccess;
using SharedLib.XmlDataModel;

namespace Tracy.DataAccess
{
    public abstract class TracyXmlDataProvider<T> : XmlDataProvider<T> where T : XmlDataModelWithAttributesAndID, new()
    {
        protected override void DoAddItem(T rawItem)
        {
            TracyFacade.Instance.ExceptionManager.Process(() =>
            {
                base.DoAddItem(rawItem);
            }, "DataAccess Policy");
            TracyFacade.Instance.LogWriter.Write("Added new " + typeof(T).Name + " ID: " + rawItem.ID);
        }

        protected override void DoUpdateItem(T oldItem, T newItem)
        {
            TracyFacade.Instance.ExceptionManager.Process(() =>
            {
                base.DoUpdateItem(oldItem, newItem);
            }, "DataAccess Policy");
            TracyFacade.Instance.LogWriter.Write("Updated " + typeof(T).Name + " ID: " + newItem.ID);
        }

        protected override void DoRemoveItem(T item)
        {
            TracyFacade.Instance.ExceptionManager.Process(() =>
            {
                base.DoRemoveItem(item);
            }, "DataAccess Policy");
            TracyFacade.Instance.LogWriter.Write("Removed " + typeof(T).Name + " ID: " + item.ID);
        }
    }
}
